# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'identification.ui'
#
# Created: Tue Jun 29 11:09:26 2010
#	  by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class identifWidget(QtGui.QDialog):

	def __init__(self, parent =None):
		QtGui.QDialog.__init__(self, parent)
		self.setupUi()
		#by default: -C 1-95 -H 1-190 -N 0-20 -O 1-80 -P 0-12 -S 0-9
		self.data ={"C":"1-20", "H":"1-40", "N":"0-20", "O": "1-30","P":"0-5", "S":"0-5"}
		QtCore.QObject.connect(self.push, QtCore.SIGNAL("clicked()"),self.launch_second)

	def setupUi(self):
		self.resize(400, 150)
		self.verticalLayout = QtGui.QVBoxLayout(self)
		
		gr = QtGui.QGroupBox("Files options", self)
		vb3 = QtGui.QVBoxLayout()
		self.pushButton = QtGui.QPushButton(self)
		self.pushButton.setMaximumSize(QtCore.QSize(150, 16777215))
		vb3.addWidget(self.pushButton)
		self.label = QtGui.QLabel(self)
		self.label.setMaximumSize(QtCore.QSize(16777215, 200))
		vb3.addWidget(self.label)
		self.lineEdit = QtGui.QLineEdit(self)
		vb3.addWidget(self.lineEdit)
		self.pushButton_2 = QtGui.QPushButton(self)
		self.pushButton_2.setMaximumSize(QtCore.QSize(50, 16777215))
		vb3.addWidget(self.pushButton_2)
		vb3.addWidget(QtGui.QLabel("Or, please enter several mass (separation -;-) :"))
		self.le =QtGui.QLineEdit(self)
		vb3.addWidget(self.le)
		gr.setLayout(vb3)
		self.verticalLayout.addWidget(gr)
		
		gr4 = QtGui.QGroupBox("Options", self)
		self.gridLayout = QtGui.QGridLayout()
		self.label_2 = QtGui.QLabel(self)
		self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
		self.spinBox = QtGui.QSpinBox(self)
		self.spinBox.setMaximumSize(QtCore.QSize(200, 16777215))
		self.gridLayout.addWidget(self.spinBox, 0, 1, 1, 1)
		self.label_3 = QtGui.QLabel(self)
		self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
		self.lineEdit_2 = QtGui.QLineEdit(self)
		self.lineEdit_2.setMaximumSize(QtCore.QSize(200, 16777215))
		self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1)
		self.max_top_hits = QtGui.QLabel("Max hits :", self)
		self.spin_hit = QtGui.QSpinBox(self)
		self.gridLayout.addWidget(self.max_top_hits, 0, 3, 1, 1)
		self.gridLayout.addWidget(self.spin_hit, 0, 4, 1, 1)
		self.buttonBox = QtGui.QDialogButtonBox(self)
		self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
		#self.gridLayout.addWidget(self.buttonBox, 2, 1, 1, 1)
		#self.verticalLayout.addLayout(self.gridLayout)
		gr4.setLayout(self.gridLayout)
		self.verticalLayout.addWidget(gr4)
		
		self.verticalLayout.addItem(QtGui.QSpacerItem(40,20))
		
		#alphabet
		gr5 = QtGui.QGroupBox("Alphabet", self)
		vb4 =QtGui.QVBoxLayout()
		self.lineEdit_3 =QtGui.QLineEdit(self)
		vb4.addWidget(self.lineEdit_3)
		self.push=QtGui.QPushButton("number of element", self)
		vb4.addWidget(self.push)
		gr5.setLayout(vb4)
		self.verticalLayout.addWidget(gr5)
		
		self.verticalLayout.addItem(QtGui.QSpacerItem(40,20))
		
		hb= QtGui.QHBoxLayout()
		# filtering
		gr1 = QtGui.QGroupBox("Filtering Options", self)
		self.checkBox_4 =QtGui.QCheckBox("idms filter", self)
		self.checkBox_6 =QtGui.QCheckBox("Phosphate filter(phosphmet screening project)", self)
		self.checkBox_7 =QtGui.QCheckBox("Smiles formula filter", self)
		vb =QtGui.QVBoxLayout()
		#vb.addWidget(self.checkBox_3)
		vb.addWidget(self.checkBox_4)
		vb.addWidget(self.checkBox_6)
		vb.addWidget(self.checkBox_7)
		gr1.setLayout(vb)
		hb.addWidget(gr1)
		#self.verticalLayout.addWidget(gr1)
		#self.verticalLayout.addItem(QtGui.QSpacerItem(40,20))

		#databases
		gr2  = QtGui.QGroupBox("DataBases", self)
		vb2 =QtGui.QVBoxLayout()
		self.databases =QtGui.QLabel("Search in :")
		vb2.addWidget(self.databases)
		self.checkBox =QtGui.QCheckBox("KEGG", self)
		vb2.addWidget(self.checkBox)
		self.checkBox_2=QtGui.QCheckBox("Metabolome JP", self)
		vb2.addWidget(self.checkBox_2)
		self.checkBox_5=QtGui.QCheckBox("BioCyc", self)
		vb2.addWidget(self.checkBox_5)
		gr2.setLayout(vb2)
		hb.addWidget(gr2)
		
		self.verticalLayout.addLayout(hb)
		
		self.verticalLayout.addWidget(self.buttonBox)

		
		self.retranslateUi()

	def retranslateUi(self):
		self.setWindowTitle(QtGui.QApplication.translate("Dialog", "Identification Parameters", None, QtGui.QApplication.UnicodeUTF8))
		self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Get Integrated files", None, QtGui.QApplication.UnicodeUTF8))
		self.label.setText(QtGui.QApplication.translate("Dialog", "File name : ", None, QtGui.QApplication.UnicodeUTF8))
		self.pushButton_2.setText(QtGui.QApplication.translate("Dialog", "...", None, QtGui.QApplication.UnicodeUTF8))
		self.label_2.setText(QtGui.QApplication.translate("Dialog", "Charge", None, QtGui.QApplication.UnicodeUTF8))
		self.label_3.setText(QtGui.QApplication.translate("Dialog", "Mmu :", None, QtGui.QApplication.UnicodeUTF8))
		

	def initialize(self):
		self.lineEdit_3.setText("CHNOPS")
		self.spinBox.setValue(1)
		self.lineEdit_2.setText("500")
	
	def printing(self,lspl):
		line=""
		for index, filename in enumerate (lspl.getFiles()):
			if not index: 
				line += filename
			else :
				line += ";" +filename
		if self.lineEdit.text() == "":
			self.lineEdit.setText( line )
		else:
			self.lineEdit.setText(self.widget.lineEdit.text() + ", " + line)
			
	def launch_second(self):
		sec =SecondaryWidget(self.lineEdit_3.text(),self.data, self)
		sec.exec_()
			
class SecondaryWidget(QtGui.QDialog):

	def __init__(self, alphabet, data, parent=None):
		QtGui.QDialog.__init__(self, parent)
		self.alphabet = alphabet
		self.line_edit =[]
		self.labels=[]
		self.data =data
		self.setupUi()

		
		QtCore.QObject.connect(self.button_box, QtCore.SIGNAL("accepted()"),self.get_data)
		QtCore.QObject.connect(self.button_box, QtCore.SIGNAL("rejected()"),self.rejected)
	
	def rejected(self):
		self.close()
		
	def setupUi(self):
	
		self.verticalLayout = QtGui.QVBoxLayout(self)
		self.label=QtGui.QLabel("Enter wanted number of element (ie min-max):")
		self.verticalLayout.addWidget(self.label)
		for letter in self.alphabet:
			hl = QtGui.QHBoxLayout()
			label = QtGui.QLabel(letter+" :")
			self.labels.append(label)
			if letter in self.data.keys():
				n =QtGui.QLineEdit(self.data[str(letter)])
				
			else:
				n =QtGui.QLineEdit("1-30")
			self.line_edit.append(n)
			hl.addWidget(label)
			hl.addWidget(n)
			#self.data[label] = n
			self.verticalLayout.addLayout(hl)
		self.button_box =QtGui.QDialogButtonBox(self)
		self.button_box.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
		self.verticalLayout.addWidget(self.button_box)
		
	def get_data(self):
		self.data={}
		for i in xrange (len(self.labels)):
			self.data[str(self.labels[i].text().split(" ")[0])] =str(self.line_edit[i].text())
		self.close()
		self.parent().data =self.data
		
